<html>
<head><meta charset="utf-8"><title>cargo fails with cfg dependencies · t-cargo · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/index.html">t-cargo</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/cargo.20fails.20with.20cfg.20dependencies.html">cargo fails with cfg dependencies</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="209300900"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/cargo%20fails%20with%20cfg%20dependencies/near/209300900" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jurgis Balciunas <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/cargo.20fails.20with.20cfg.20dependencies.html#209300900">(Sep 07 2020 at 14:20)</a>:</h4>
<p>Hey, I'm trying to include a crate that uses <code>cfg</code> for architecture specific dependencies, but for some reason it tries to include packages even when cfg evaluates to false.</p>
<p>For example I have this in dependency <code>cargo.toml</code> (async-embedded):</p>
<div class="codehilite"><pre><span></span><code>[target.&#39;cfg(false)&#39;.dependencies]
riscv = &quot;0.5.6&quot;
</code></pre></div>


<p>And then in my main project <code>cargo update</code> fails with:</p>
<div class="codehilite"><pre><span></span><code>error: failed to select a version for `bare-metal`.
    ... required by package `stm32f4xx-hal v0.8.0`
    ... which is depended on by `gimbal-ctrl v0.1.0 (C:\Users\User\Documents\Dev\gimbal-ctrl)`
versions that meet the requirements `^0.2.5` are: 0.2.5

all possible versions conflict with previously selected packages.

  previously selected package `bare-metal v0.2.1`
    ... which is depended on by `riscv v0.5.6`
    ... which is depended on by `async-embedded v0.0.0-alpha.0 (C:\Users\User\Documents\Dev\async-on-embedded\async-embedded)`
    ... which is depended on by `gimbal-ctrl v0.1.0 (C:\Users\User\Documents\Dev\gimbal-ctrl)`

failed to select a version for `bare-metal` which could resolve this conflict
</code></pre></div>


<p>So even though <code>riscv</code> dependency is not getting built (is disabled by cfg), cargo still tries to match dependency versions and fails. Is this a bug with cargo or something wrong with my setup?</p>



<a name="209301071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/cargo%20fails%20with%20cfg%20dependencies/near/209301071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/cargo.20fails.20with.20cfg.20dependencies.html#209301071">(Sep 07 2020 at 14:22)</a>:</h4>
<p>When resolution is performed, it assumes all <code>cfg</code> expressions are true.  This is so that it resolves the same no matter what target or platform you are using.</p>



<a name="209301345"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/cargo%20fails%20with%20cfg%20dependencies/near/209301345" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jurgis Balciunas <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/cargo.20fails.20with.20cfg.20dependencies.html#209301345">(Sep 07 2020 at 14:25)</a>:</h4>
<p>I see, that explains it. Are there any workarounds for this without forking crate and removing all other archs from <code>cargo.toml</code>? It seems quite problematic for crates with multiple cfg archs</p>



<a name="209301722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/cargo%20fails%20with%20cfg%20dependencies/near/209301722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/cargo.20fails.20with.20cfg.20dependencies.html#209301722">(Sep 07 2020 at 14:29)</a>:</h4>
<p>In this specific case, I don't see an immediate solution.  Those two packages have conflicting requirements.  It looks like <code>riscv 0.6.0</code> no longer has the restriction, so maybe try to see if <code>async-embedded</code> can use that instead?</p>



<a name="209302479"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/cargo%20fails%20with%20cfg%20dependencies/near/209302479" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jurgis Balciunas <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/cargo.20fails.20with.20cfg.20dependencies.html#209302479">(Sep 07 2020 at 14:38)</a>:</h4>
<p>Yeah seems like the only option. Submitting a PR for them. Thanks for the help!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>